﻿using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using MapEditor.Tiles;

namespace MapEditor.Tools
{
    class Marquee : Tool
    {
        private readonly Selection selection;

        public Marquee(Selection selection)
        {
            this.selection = selection;
        }

        public override void Use(TileLayer layer, int tileX, int tileY, TileType tileType, int type, bool showGrid)
        {
            for (int x = 0; x < selection.Rectangle.Width / layer.TileSize; x ++)
            {
                for (int y = 0; y < selection.Rectangle.Height / layer.TileSize; y ++)
                {
                    //Rectangle r = new Rectangle(selectorRect.X, selectorRect.Y, selection.Rectangle.Width - (x * layer.TileSize), selection.Rectangle.Height - (y * layer.TileSize));

                    //PaintArea(layer, x + (selection.Rectangle.X / layer.TileSize), y + (selection.Rectangle.Y / layer.TileSize), r, tileType, type);

                    PaintArea(layer, x + (selection.Rectangle.X / layer.TileSize), y + (selection.Rectangle.Y / layer.TileSize), tileType, type, showGrid);
                }
            }
        }

        public override void DrawRegularTilePreview(SpriteBatch spriteBatch, Texture2D tilesetTexture, Rectangle previewRect)
        {
            if (PaintType == PaintingType.Drawing)
            {
                selection.DrawMarqueeSelectorPreview(spriteBatch, tilesetTexture);
            }
        }

        public override void DrawCustomTilePreview(SpriteBatch spriteBatch, Rectangle previewRect, TileType tileType)
        {
            if (PaintType == PaintingType.Drawing)
            {
                Utility.DrawCustomTile(spriteBatch, previewRect, tileType);
            }
        }

        public override Rectangle PreviewRect
        {
            get
            {
                return (PaintType == PaintingType.Drawing || PaintType == PaintingType.Erasing) ? selection.Rectangle : Rectangle.Empty;
            }
        }

        public override Rectangle PreviewRectNoGrid
        {
            get
            {
                return Rectangle.Empty;
            }
        }

    }
}
